/**
    @project {
        "templateId": "org.helgoboss.custom",
        "version": "0.1-SNAPSHOT",
        "dependencies": [
            "org.scala-lang:scala-library:2.9.0-1"
        ]
    }
*/

package org.helgoboss.commandlet

/**
 * An instance of this type represents an executable command.
 */
trait Commandlet {
    /**
     * A string that should identify this commandlet uniquely within the target system.
     */
    val id: String

    /**
     * Executes the command within the given execution context.
     *
     * @returns exit code (exit code 0 indicates a successfull execution)
     */
    def execute(executionContext: ExecutionContext): Int
}


import java.io._

/**
 * An instance of this type represents the context for a commandlet execution. The interface is tailored to the context of a
 * typical operating-system console command. It supports arguments, input stream, output stream etc.
 * The interface is intentionally very thin and clean. It doesn't contain any convenience methods. These can be added by the client using
 * decoration, for example.
 */
trait ExecutionContext {
    val workingDirectory: File
    val arguments: Seq[String]
    val inputStream: InputStream
    val outputStream: PrintStream
}
